<template>
    <div class="container_box">
        <el-scrollbar class="main_box">
            <div class="newCommonList">
                <el-form :model="form" label-width="auto">
                    <el-row>
                        <el-col :span="12"
                            ><el-form-item label="公海名称" required>
                                <el-input
                                    v-model="form.name"
                                    placeholder="请输入公海名称"
                                    :disabled="isread"
                                    show-word-limit
                                    maxlength="15"></el-input> </el-form-item
                        ></el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="20"
                            ><el-form-item label="公海管理员" prop="emplou" required>
                                <div v-if="!isread" class="staffs">
                                    <el-tag
                                        v-for="item in creators"
                                        :key="item.name"
                                        class="staffs_item"
                                        closable
                                        @close="handleClose(item)">
                                        {{ item.name }}
                                    </el-tag>
                                </div>
                                <div v-if="isread" class="staffs">
                                    <el-tag
                                        v-for="item in creators"
                                        :key="item.name"
                                        class="staffs_item"
                                        :closable="false"
                                        :type="item.id">
                                        {{ item.name }}
                                    </el-tag>
                                </div>
                                <el-button v-if="!isread" @click="openDepart(1)">选择员工</el-button></el-form-item
                            ></el-col
                        >
                    </el-row>
                    <el-row>
                        <el-col :span="20"
                            ><el-form-item label="可见部门" prop="dept" required>
                                <div v-if="!isread" class="staffs">
                                    <el-tag
                                        v-for="item in deptData"
                                        :key="item.name"
                                        class="staffs_depart"
                                        closable
                                        @close="closedept(item)">
                                        {{ item.name }}
                                    </el-tag>
                                </div>
                                <div v-if="isread" class="staffs">
                                    <el-tag
                                        v-for="item in deptData"
                                        :key="item.name"
                                        class="staffs_depart"
                                        :closable="false">
                                        {{ item.name }}
                                    </el-tag>
                                </div>
                                <el-button v-if="!isread" @click="open">选择部门</el-button></el-form-item
                            ></el-col
                        >
                    </el-row>
                    <el-row>
                        <el-col :span="20"
                            ><el-form-item label="分配方式">
                                <el-radio-group v-model="form.apply_rule_type" :disabled="isread">
                                    <el-radio :label="1">手动领取</el-radio>
                                    <el-radio :label="2">自动分配</el-radio>
                                    <el-radio :label="3">公海管理员分配</el-radio>
                                </el-radio-group>
                                <div v-if="form.apply_rule_type == 2">
                                    <el-radio-group v-model="form.apply_type" :disabled="isread">
                                        <el-radio :label="1">随机分配</el-radio>
                                        <el-radio :label="2">平均分配</el-radio>
                                    </el-radio-group>
                                </div>
                                <div v-if="form.apply_rule_type == 1">
                                    <el-radio-group v-model="form.is_limit" :disabled="isread"
                                        >fa
                                        <el-radio :label="1">限制</el-radio>
                                        <el-radio :label="2">不限</el-radio>
                                    </el-radio-group>
                                </div>
                                <div v-if="form.apply_rule_type == 1 && form.is_limit == 1">
                                    <el-form-item label="每日领取数量" class="space">
                                        <el-input
                                            v-model="form.receive_qty.per_day"
                                            :disabled="isread"
                                            @change="
                                                inputchange(form.receive_qty.per_day, 1)
                                            "></el-input> </el-form-item
                                    ><el-form-item label="每月领取数量" class="space">
                                        <el-input
                                            v-model="form.receive_qty.per_month"
                                            :disabled="isread"
                                            @change="
                                                inputchange(form.receive_qty.per_month, 2)
                                            "></el-input> </el-form-item
                                    ><el-form-item label="总领取数量" class="space">
                                        <el-input
                                            v-model="form.receive_qty.total"
                                            :disabled="isread"
                                            @change="inputchange(form.receive_qty.total, 3)"></el-input>
                                    </el-form-item></div></el-form-item
                        ></el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="20"
                            ><el-form-item class="m_r_b line_h" label="回收方式">
                                <el-radio-group v-model="form.is_recovery" :disabled="isread">
                                    <el-radio :label="1">不回收</el-radio>
                                    <el-radio :label="2">自定义回收</el-radio>
                                </el-radio-group>

                                <div v-if="form.is_recovery == 2" class="transcontent">
                                    <div class="ruleText">至公海</div>
                                    <div style="display: flex; justify-content: space-between; white-space: nowrap">
                                        <el-radio-group
                                            v-model="form.recovery_seas_type"
                                            :disabled="isread"
                                            @change="changeClub">
                                            <el-radio :label="1">当前公海</el-radio>
                                            <el-radio :label="2">其他公海</el-radio> </el-radio-group
                                        >&nbsp;<el-select
                                            v-show="form.recovery_seas_type === 2"
                                            v-model="form.recovery_seas_id"
                                            :disabled="isread"
                                            ><el-option
                                                v-for="(item, index) in seaids"
                                                :key="index"
                                                :value="item.id"
                                                :label="item.name"
                                                >{{ item.name }}</el-option
                                            ></el-select
                                        >
                                    </div>
                                </div>
                                <div v-if="form.is_recovery == 2" class="transcontent">
                                    <div class="ruleText">回收规则</div>
                                    <div class="transRight">
                                        <div v-if="form.recovery_rule.length" class="transrule">
                                            <div
                                                v-for="(item, index) in form.recovery_rule"
                                                :key="index"
                                                class="transcolumn">
                                                <div class="transall">
                                                    <div class="left"><div class="circle"></div></div>
                                                    <div class="right transall">
                                                        <span>规则{{ index + 1 }}：超过&nbsp;</span>
                                                        <el-input-number
                                                            v-model="item.beyond_days"
                                                            style="width: 100px"
                                                            controls-position="right"
                                                            :disabled="isread"
                                                            :min="0"></el-input-number
                                                        ><span>&nbsp;天&nbsp;</span
                                                        ><el-input-number
                                                            v-model="item.beyond_hours"
                                                            style="width: 120px"
                                                            :disabled="isread"
                                                            :min="0"
                                                            :max="23"
                                                            controls-position="right"></el-input-number
                                                        ><span>&nbsp;时，未执行&nbsp;</span
                                                        ><el-select
                                                            v-model="item.not_do_type"
                                                            placeholder="请选择有效行为"
                                                            style="width: 140px"
                                                            :disabled="isread">
                                                            <el-option label="添加跟进" :value="1"></el-option>
                                                            <el-option
                                                                label="修改线索信息"
                                                                :value="2"></el-option> </el-select
                                                        ><img
                                                            v-if="!isread"
                                                            src="@/assets/delete.png"
                                                            class="tramsimg"
                                                            @click="deleteRule(index)" />
                                                    </div>
                                                </div>
                                                <div v-if="form.recovery_rule.length !== index + 1" class="center">
                                                    <div class="line"></div>
                                                    <span class="text">或</span>
                                                    <div class="line"></div>
                                                </div>
                                            </div>
                                        </div>
                                        <el-button
                                            v-if="!isread"
                                            :disabled="form.recovery_rule.length >= 10"
                                            @click="addtransrule"
                                            >添加规则</el-button
                                        >
                                    </div>
                                    <el-button
                                        v-if="!isread"
                                        :disabled="form.recovery_rule.length >= 10"
                                        @click="addtransrule"
                                        >添加规则</el-button
                                    >
                                </div>
                                <div v-if="form.is_recovery == 2">
                                    <div class="transcontent">
                                        <div class="ruleText">执行对象</div>
                                        <div>
                                            <el-radio-group v-model="form.recovery_type" :disabled="isread">
                                                <el-radio :label="1">公海员工统一执行</el-radio>
                                                <el-radio :label="2">指定员工执行</el-radio>
                                            </el-radio-group>
                                            <div v-if="form.recovery_type == 2" class="staffs">
                                                <template v-if="!isread">
                                                    <el-tag
                                                        v-for="item in twocreators"
                                                        :key="item.name"
                                                        class="staffs_item"
                                                        closable
                                                        @close="handleClose(item)">
                                                        {{ item.name }}
                                                    </el-tag> </template
                                                ><template v-if="isread">
                                                    <el-tag
                                                        v-for="item in twocreators"
                                                        :key="item.name"
                                                        class="staffs_item"
                                                        :closable="false">
                                                        {{ item.name }}
                                                    </el-tag>
                                                </template>
                                            </div>
                                            <template v-if="!isread"
                                                ><el-button
                                                    v-if="form.recovery_type == 2 && !isread"
                                                    @click="openDepart(2)"
                                                    >选择员工</el-button
                                                ></template
                                            >
                                        </div>
                                    </div>
                                    <!-- <div v-if="form.recovery_remind" style="color: #606266"
                >回收前&nbsp;<el-input v-model="form.recovery_remind_before" style="width: 100px" :disabled="isread"></el-input>&nbsp;天&nbsp;<el-time-picker
                  v-model="form.recovery_remind_before_time"
                  value-format="HH:mm:ss"
                  placeholder="选择时间"
                  :disabled="isread"
                />&nbsp;提醒员工</div
              > -->
                                </div>
                                <div v-if="form.is_recovery == 2">
                                    <div class="transcontent">
                                        <div class="ruleText">回收提醒</div>
                                        <div>
                                            <el-switch
                                                v-model="form.recovery_remind"
                                                :disabled="isread"
                                                :active-value="1"
                                                :inactive-value="2" />
                                            <div v-if="form.recovery_remind == 1" style="color: #606266">
                                                回收前&nbsp;<el-input
                                                    v-model="form.recovery_remind_before"
                                                    style="width: 100px"
                                                    :disabled="isread"
                                                    min="1"
                                                    type="number"
                                                    @change="inputchange(form.recovery_remind_before, 4)"></el-input
                                                >&nbsp;天&nbsp;<el-time-picker
                                                    v-model="form.recovery_remind_before_time"
                                                    value-format="HH:mm:ss"
                                                    placeholder="选择时间"
                                                    :disabled="isread" />&nbsp;提醒员工
                                            </div>
                                        </div>
                                    </div>
                                    <el-button
                                        v-if="!isread"
                                        style="margin-bottom: 13px"
                                        :disabled="form.transfer_condition.length >= 10"
                                        @click="addrule"
                                        >添加条件</el-button
                                    >
                                </div>
                            </el-form-item></el-col
                        >
                    </el-row>
                    <el-row>
                        <el-col :span="20"
                            ><el-form-item label="员工回捡" class="m_r_b">
                                <el-switch
                                    v-model="form.staff_check"
                                    :disabled="isread"
                                    :active-value="1"
                                    :inactive-value="2"></el-switch>
                                <div v-if="form.staff_check == 1" style="color: #606266">
                                    退回&nbsp;<el-input
                                        v-model="form.staff_check_delay"
                                        style="width: 100px"
                                        :disabled="isread"
                                        min="1"
                                        type="number"
                                        @change="inputchange(form.staff_check_delay, 5)"></el-input
                                    >&nbsp;天后，才可以重新认领
                                </div>
                            </el-form-item></el-col
                        >
                    </el-row>
                    <el-row>
                        <el-col :span="20"
                            ><el-form-item label="转化规则">
                                <el-radio-group v-model="form.transfer_type" :disabled="isread">
                                    <el-radio :label="1">员工手动转化</el-radio>
                                    <el-radio :label="2">自动转化客户</el-radio>
                                </el-radio-group>
                                <div v-if="form.transfer_type == 2" class="transcontent">
                                    <div class="ruleText">转化条件</div>
                                    <div class="transRight">
                                        <div v-if="form.transfer_condition.length" class="transrule">
                                            <div
                                                v-for="(item, index) in form.transfer_condition"
                                                :key="index"
                                                class="transcolumn">
                                                <div class="transall">
                                                    <div class="left"><div class="circle"></div></div>
                                                    <div class="right transall">
                                                        <span>条件{{ index + 1 }}：当线索&nbsp;</span
                                                        ><el-select
                                                            v-model="item.clue_attr_id"
                                                            placeholder="请选择线索属性"
                                                            style="width: 150px"
                                                            :disabled="isread">
                                                            <el-option
                                                                v-for="item in setingid"
                                                                :key="item.id"
                                                                :label="item.name"
                                                                :value="item.id"></el-option> </el-select
                                                        ><span>&nbsp;不为空</span
                                                        ><img
                                                            v-if="!isread"
                                                            src="@/assets/delete.png"
                                                            class="tramsimg"
                                                            @click="deleteRecycleRule(index)" />
                                                    </div>
                                                </div>
                                                <div v-if="form.transfer_condition.length !== index + 1" class="center">
                                                    <div class="line"></div>
                                                    <span class="text">或</span>
                                                    <div class="line"></div>
                                                </div>
                                            </div>
                                        </div>
                                        <el-button
                                            v-if="!isread"
                                            style="margin-bottom: 13px"
                                            :disabled="form.transfer_condition.length >= 10"
                                            @click="addrule"
                                            >添加条件</el-button
                                        >
                                    </div>
                                </div>
                                <div v-if="form.transfer_type == 2" class="transcontent">
                                    <div class="ruleText">转化周期</div>
                                    <div>
                                        <el-radio-group
                                            v-model="form.cycle_type"
                                            style="line-height: 20px"
                                            :disabled="isread">
                                            <el-radio :label="1">实时转化</el-radio>
                                            <el-radio :label="2">周期批量转化</el-radio>
                                        </el-radio-group>
                                        <div v-if="form.cycle_type == 1" class="transcontent m_r_t">
                                            <div class="ruleText">行为触点：</div>
                                            <el-checkbox-group v-model="form.behavior_contact" :disabled="isread">
                                                <el-checkbox :label="1" name="type">新增线索</el-checkbox>
                                                <el-checkbox :label="2" name="type">修改线索信息</el-checkbox>
                                                <el-checkbox :label="3" name="type">添加跟进</el-checkbox>
                                            </el-checkbox-group>
                                        </div>
                                        <div v-if="form.cycle_type == 2" class="transcontent">
                                            每&nbsp;<el-input
                                                v-model="form.cycle_config.cycle_days"
                                                style="width: 100px"
                                                :disabled="isread"
                                                min="1"
                                                type="number"
                                                @change="inputchange(form.cycle_config.cycle_days, 6)"></el-input
                                            >&nbsp;天&nbsp;<el-time-picker
                                                v-model="form.cycle_config.time"
                                                value-format="HH:mm:ss"
                                                placeholder="选择时间"
                                                :disabled="isread" />&nbsp;执行一次
                                        </div>
                                    </div>
                                </div>
                            </el-form-item></el-col
                        >
                    </el-row>
                    <!-- <el-row>
        <el-col :span="12"
          ><el-form-item label="客户合并规则">
            <el-switch v-model="form.combine" :active-value="1" :inactive-value="2"></el-switch>
            <div v-if="form.combine==1"
              ><el-radio-group v-model="form.combinetype" class="radioContent">
                <el-radio label="1">手机号匹配</el-radio>
                <el-radio label="2">微信unionId</el-radio>
                <el-radio label="3">抖音用户ID</el-radio>
              </el-radio-group>
            </div></el-form-item
          ></el-col
        >
      </el-row> -->
                </el-form>

                <ZWDepart ref="DepartRef" type="1" @submit="getDepart" />
                <!--选择部门 -->
                <ZWDepartment
                    v-model:show="showdepat"
                    :is-member="false"
                    :selected-member="deptData"
                    @submit="getDepart1" />
            </div>
        </el-scrollbar>
        <div class="footer_box">
            <el-button @click="router.go(-1)">取消</el-button
            ><el-button v-if="!isread" type="primary" @click="save">保存</el-button>
        </div>
    </div>
</template>
<script lang="ts" setup>
import { ref, reactive } from 'vue';
import { ElMessage } from 'element-plus';
import router from '@/router';
import ZWDepart from '@/components/ZWDepart.vue';
import ZWDepartment from '@/components/zw/department/Department';
import { getSetionId } from '@/utils/utils';
import { seaList, getClubSetting, newSea, seaDetail } from '@/api/customer/clubManage/commonSea';
import { fetchTreeList } from '@/api/employe/employeemanage/manage';
const isread = router.currentRoute.value.query.text ? true : false;
const deptType = ref(1); //1是管理员员工弹框 2是回收方式指定员工弹框
const form = reactive({
    name: '', //公海名称
    admin_user: [], //管理id数组
    visble_department: [], //可见部门id数组
    apply_rule_type: 1, //分配规则类型 1手动领取。2自动分配 3管理员分配
    is_limit: 1, //是否限制领取数
    apply_type: 1,
    receive_qty: {
        per_day: '', //每天限制
        per_month: '', //每月限制
        total: '' //总限制
    }, //领取限制
    recovery_type: 1, //回收规则 2制定员工 1公海统一回收
    is_recovery: 1, //是否回收  1 不回收 2自定义回收
    execute_staff: [], //指定定员工
    recovery_seas_type: 1, //1 当前公海  2指定公海
    recovery_seas_id: '', //回收公海id
    recovery_rule: [], //回收规则
    staff_check: 2, //员工回捡开关 1 开启 2关闭
    staff_check_delay: 1, //员工回捡相隔天数
    recovery_remind: 2, //回收提醒开关
    recovery_remind_before: 1, //回收前多少天提醒
    recovery_remind_before_time: '',
    transfer_type: 1, //转化类型 1手动2自动
    transfer_condition: [], //转化条件
    cycle_type: 1, //转化周期
    behavior_contact: [1], //行为触点
    cycle_config: {
        cycle_days: 1, //天数
        time: '' //时间
    } //转化配
});
const twocreators = ref([]);
const creators = ref([]);
const deptData = ref([]); //选择的部门列表
const DepartRef = ref(null);
const seaids = ref([]); //公海列表
const setingid = ref([]); //线索属性列表
const inputchange = (val: any, num: any) => {
    const req = /^\d+$/;
    if (!req.test(val)) {
        ElMessage.warning('请输入正整数');
        if (num == 1) {
            form.receive_qty.per_day = '';
        } else if (num == 2) {
            form.receive_qty.per_month = '';
        } else if (num == 3) {
            form.receive_qty.total = '';
        } else if (num == 4) {
            form.recovery_remind_before = '';
        } else if (num == 5) {
            form.staff_check_delay = '';
        } else {
            form.cycle_config.cycle_days = '';
        }
    } else {
        if (num == 1) {
            if (form.receive_qty.per_month && Number(form.receive_qty.per_month) < Number(form.receive_qty.per_day)) {
                form.receive_qty.per_day = '';
                ElMessage.warning('每日领取数量要不能大于每月领取数量');
            }
        } else if (num == 2) {
            if (form.receive_qty.per_day && Number(form.receive_qty.per_day) > Number(form.receive_qty.per_month)) {
                form.receive_qty.per_month = '';
                ElMessage.warning('每月领取数量要不能小于每日领取数量');
            }
        } else if (num == 3) {
            if (form.receive_qty.per_day && Number(form.receive_qty.per_day) > Number(form.receive_qty.total)) {
                form.receive_qty.total = '';
                ElMessage.warning('总领取数量要不能小于每日领取数量');
            }
            if (form.receive_qty.per_month && Number(form.receive_qty.per_month) > Number(form.receive_qty.total)) {
                form.receive_qty.total = '';
                ElMessage.warning('总领取数量要不能小于每月领取数量');
            }
        }
    }
};
//获取公海列表
const getSeaList = () => {
    seaList({ page: 1, page_size: 99, is_not_list: 1 }).then((res: any) => {
        seaids.value = res.data;
    });
};
//获取线索属性
const getclub = () => {
    getClubSetting({ page: 1, page_size: 99 }).then((res: any) => {
        res.data.forEach(item => {
            if (item.is_enable == 1) {
                setingid.value.push(item);
            }
        });
    });
};
// 编辑时数据回显
const recursion = (data: any, selectArr: any) => {
    data.forEach((item: any) => {
        if (item.children && item.children.length > 0) {
            recursion(item.children, selectArr);
        } else {
            if (selectArr.includes(item.id)) {
                item.check = true;
            } else {
                item.check = false;
            }
        }
    });
};
//获取公海数据
const getSeaData = () => {
    if (router.currentRoute.value.query.id) {
        seaDetail({ id: router.currentRoute.value.query.id }).then(res => {
            creators.value = res.admin_user;
            deptData.value = res.visble_department;
            twocreators.value = res.execute_staff;
            setTimeout(() => {}, 1000);
            res.visble_department = getSetionId('id', res.visble_department);
            res.admin_user = getSetionId('id', res.admin_user);
            res.execute_staff = getSetionId('id', res.execute_staff);
            // res.recovery_remind = res.recovery_remind;
            // res.staff_check = res.staff_check;
            Object.assign(form, res);
            if (form.apply_rule_type == 1) {
                form.apply_type = 1;
            } else if (form.apply_rule_type == 2) {
                form.is_limit = 1;
            }
            if (form.is_recovery == 1) {
                form.recovery_seas_type = 1;
                form.recovery_type = 1;
            }
        });
    }
};

getSeaData();
getclub();
getSeaList();
//获取部门树

const openDepart = (data: any) => {
    // 记录是那个员工弹框
    deptType.value = data;
    DepartRef.value.departVisble = true;
    DepartRef.value.selectedMember = data == 1 ? [...creators.value] : [...twocreators.value];
};
const open = () => {
    showdepat.value = !showdepat.value;
};
// 获取部门成员
const getDepart = (res: any) => {
    if (deptType.value == 1) {
        creators.value = res;
        form.admin_user = getSetionId('id', creators.value);
    } else {
        twocreators.value = res;
        form.execute_staff = getSetionId('id', twocreators.value);
    }
};
// 员工移除
const handleClose = (data: any) => {
    if (deptType.value == 1) {
        creators.value = creators.value.filter((item: any) => item.id !== data.id);
        form.admin_user = getSetionId('id', creators.value);
    } else {
        twocreators.value = twocreators.value.filter((item: any) => item.id !== data.id);
        form.work_two_list = getSetionId('id', twocreators.value);
    }

    DepartRef.value.removeItem(data);
};

const showdepat = ref(false);
const openDeprtment = () => {
    showdepat.value = !showdepat.value;
};

const getDepart1 = (val: any) => {
    form.visble_department = val.map((v: any) => v.id);
    deptData.value = val;
    showdepat.value = false;
};

const closedept = (data: any) => {
    deptData.value = deptData.value?.filter((item: any) => item.id != data.id);
};
//添加转化规则条件
const addrule = () => {
    form.transfer_condition.push({
        clue_attr_id: '' //线索属性id
    });
};
// 删除转化规则条件
const deleteRecycleRule = (data: any) => {
    form.transfer_condition.splice(data, 1);
};
//删除回收规则条件
const deleteRule = (data: any) => {
    form.recovery_rule.splice(data, 1);
};
// 添加回收规则条件
const addtransrule = () => {
    form.recovery_rule.push({
        beyond_days: '', //超过多少天
        beyond_hours: '', //超过多少小时
        not_do_type: '' //未进行某些操作  1新增线索 2修改线索信息
    });
};

// 新建保存
const save = () => {
    if (!form.name) {
        ElMessage.warning('公海名称不能为空');
        return;
    }
    if (!form.admin_user.length) {
        ElMessage.warning('管理员不能为空');
        return;
    }
    if (!form.visble_department.length) {
        ElMessage.warning('可见部门不能为空');
        return;
    }
    if (form.apply_rule_type == 1 && form.is_limit == 1) {
        if (form.receive_qty.per_day == '' && form.receive_qty.per_month == '' && form.receive_qty.total == '') {
            ElMessage.warning('每日领取数量、每月领取数量和总领取数量至少填写一个');
            return;
        }
        // if (form.receive_qty.per_month == '') {
        //   ElMessage.warning('请填写每月领取数量')
        //   return
        // }
        // if (form.receive_qty.total == '') {
        //   ElMessage.warning('请填写总领取数量')
        //   return
        // }
    }
    if (form.recovery_type == 2 && !form.execute_staff.length) {
        ElMessage.warning('请选择指定员工');
        return;
    }
    if (form.is_recovery == 2) {
        if (form.recovery_seas_type == 2 && !form.recovery_seas_id) {
            ElMessage.warning('请选择其他公海');
            return;
        }
        if (!form.recovery_rule.length) {
            ElMessage.warning('请添加回收规则');
            return;
        }
        let noString = false;
        for (let i = 0; i < form.recovery_rule.length; i++) {
            const item = form.recovery_rule[i];
            if (!item.beyond_days) {
                ElMessage.warning(`回收规则:规则${i + 1} 天数不能为空`);
                noString = true;
                break;
            }
            if (!item.beyond_hours) {
                ElMessage.warning(`回收规则:规则${i + 1} 小时不能为空`);
                noString = true;
                break;
            }
            if (!item.not_do_type) {
                ElMessage.warning(`回收规则:规则${i + 1} 请选择有效行为`);
                noString = true;
                break;
            }
            if (item.beyond_days == 0 && item.beyond_hours == 0) {
                ElMessage.warning(`回收规则:规则${i + 1}天数和小时不能同时为0`);
                noString = true;
                break;
            }
        }
        if (noString) return;
        if (form.recovery_remind == 1 && !form.recovery_remind_before && !form.recovery_remind_before_time) {
            ElMessage.warning('请填写回收提醒时间');
            return;
        }
    }
    if (form.transfer_type == 2) {
        if (!form.transfer_condition.length) {
            ElMessage.warning('请添加转化条件');
            return;
        }
        let clues = false;
        for (let i = 0; i < form.transfer_condition.length; i++) {
            const item = form.transfer_condition[i];
            if (!item.clue_attr_id) {
                ElMessage.warning(`转化条件:条件${i + 1} 当前线索不能为空`);
                clues = true;
                break;
            }
        }
        if (clues) return;
        if (form.cycle_type == 1 && !form.behavior_contact.length) {
            ElMessage.warning('请选择行为触点');
            return;
        }
        if (form.cycle_type == 2 && !form.cycle_config.cycle_days && !form.cycle_config.time) {
            ElMessage.warning('请填写转化日期');
            return;
        }
    }
    //分配方式的切换数据修改
    if (form.apply_rule_type == 1) {
        form.apply_type = '';
    } else if (form.apply_rule_type == 2) {
        form.is_limit = '';
        Object.keys(form.receive_qty).map((key, item) => {
            form.receive_qty[key] = '';
        });
    } else {
        form.apply_type = '';
        form.is_limit = '';
        Object.keys(form.receive_qty).map((key, item) => {
            form.receive_qty[key] = '';
        });
    }
    //回收方式数据修改
    if (form.is_recovery == 1) {
        form.recovery_seas_type = '';
        form.recovery_seas_id = 0;
        form.recovery_rule = [];
        form.recovery_type = '';
        form.recovery_remind = 2;
        form.recovery_remind_before = '';
        form.recovery_remind_before_time = '';
    } else if (form.is_recovery == 2) {
        if (form.recovery_seas_type == 1) {
            form.recovery_seas_id = 0;
        }
        if (form.recovery_type == 1) {
            twocreators.value = [];
            form.execute_staff = [];
        }
    }
    // 员工回检数据修改
    if (!form.staff_check) {
        form.staff_check_delay = '';
    }
    //转化规则数据修改
    if (form.transfer_type == 1) {
        form.transfer_condition = [];
        form.cycle_type = '';
        Object.keys(form.cycle_config).map((key, item) => {
            form.cycle_config[key] = '';
        });
    } else if (form.transfer_type == 2) {
        if (form.cycle_type == 1) {
            form.cycle_config.cycle_day = '';
            form.cycle_config.time = '';
        } else {
            form.behavior_contact = [];
        }
    }
    // form.recovery_remind = form.recovery_remind;
    // form.staff_check = form.staff_check;
    if (router.currentRoute.value.query.id) {
        form.id = router.currentRoute.value.query.id;
        newSea(form).then(res => {
            ElMessage.success('编辑成功');
            router.go(-1);
        });
    } else {
        newSea(form).then(res => {
            ElMessage.success('新建成功');
            router.go(-1);
        });
    }
};
const changeClub = (data: any) => {
    // if (data == 1) {
    form.recovery_seas_id = '';
    // }
};
</script>
<style scoped lang="scss">
.newCommonList {
    background: #fff;
    padding: 24px;

    .ruleText {
        color: #33302d;
        margin-right: 16px;
    }

    .transcontent {
        display: flex;

        .circle {
            width: 6px;
            height: 6px;
            border: 2px solid #ff6b00;
            border-radius: 6px;
        }

        :deep .el-checkbox {
            display: block;
        }

        .transrule {
            min-width: 400px;
            border: 1px solid #eaeaea;
            padding: 16px;
            margin-bottom: 16px;

            .transcolumn {
                .transall {
                    display: flex;
                    align-items: center;

                    .right {
                        padding-left: 16px;

                        .tramsimg {
                            margin-left: 20px;
                        }
                    }

                    .left {
                        display: flex;
                        flex-direction: column;
                        align-items: center;
                    }
                }

                .center {
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    width: 10px;
                    margin-top: -10px;

                    .text {
                        color: #ff6b00;
                    }

                    .line {
                        height: 24px;
                        width: 0;
                        border: 1px dashed #ffc69e;
                    }
                }
            }
        }
    }

    .m_r_t {
        margin-top: -9px;
    }

    :deep(span.el-tag.el-tag--light.staffs_item::before) {
        content: '';
        display: inline-block;
        width: 10px;
        height: 11px;
        background: url('@/assets/image/LiveCode/people_icon.png') center/100% no-repeat;
        margin-right: 10px;
    }

    :deep(span.el-tag.el-tag--light.staffs_depart::before) {
        content: '';
        display: inline-block;
        width: 12px;
        height: 12px;
        background: url('/static/newDepart.png') center/100% no-repeat;
        margin-right: 10px;
    }

    .staffs_item,
    .staffs_depart {
        margin-right: 10px;
    }

    .radioContent .el-radio {
        display: block;
    }

    .btn {
        border-top: 1px solid #d9d9d9;
        display: flex;
        justify-content: center;
        padding-top: 20px;
    }

    .space {
        margin-bottom: 16px;

        :deep(.el-form-item__content) {
            .el-input {
                width: 470px;
            }
        }

        &:last-of-type {
            margin-bottom: -10px;
        }
    }
}

:deep(.m_r_b) {
    margin-bottom: 0;
}

:deep(.line_h) {
    .el-form-item__content {
        line-height: 28px;
    }

    // margin-bottom: 0p/x;
}

.depart-select {
    .el-dialog__body {
        .depart-content {
            height: 500px;
            display: flex;

            // justify-content: space-between;

            .content-left {
                padding-right: 16px;
                border-right: 1px solid #eee;
                margin-right: 16px;

                .el-scrollbar {
                    margin-top: 8px;
                }

                .no-img {
                    text-align: center;
                }

                .depart-detail {
                    width: 150px;
                    display: flex;
                    flex-direction: column;

                    .search-detail {
                        color: #33302d;
                    }

                    .depart-btn {
                        margin: 0;
                    }
                }
            }

            .content-right {
                .title {
                    font-size: 14px;
                    color: #333;
                    margin-bottom: 16px;
                }

                .select-detail {
                    width: 270px;
                    height: 30px;
                    padding: 0 4px;
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    line-height: 1;
                    color: #666;
                    font-size: 12px;

                    .select_name {
                        display: flex;
                        align-items: center;
                    }

                    &:hover {
                        background-color: #f8f8f8;
                    }

                    .el-icon {
                        font-size: 20px;
                        color: #666;

                        &:hover {
                            cursor: pointer;
                            color: #ff6b00;
                        }
                    }
                }
            }
        }
    }

    .depart_icon {
        width: 15px;
        margin: 0 10px 0 2px;
        vertical-align: middle;
    }

    .depart_member {
        .depart_member_item {
            display: flex;
            align-items: center;
        }
    }
}
</style>
